package itit;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-12-22
 * Time: 14:54
 */
public class Test {

    public static void main2(String[] args) {
//        List<Integer> list1 = new LinkedList<>();
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        //迭代器Iterator的使用练习:
        Iterator<Integer> iterator = list.listIterator();
        while (iterator.hasNext()) {
            Integer next =  iterator.next();
            System.out.print(next + " ");
        }
        System.out.println();
        Iterator<Integer> iterator1 = list.listIterator();
        while (iterator1.hasNext()) {
            Integer value =  iterator1.next();
            if(value == 2)  list.remove(Integer.valueOf(2));
        }

        System.out.println(list);
    }

    //顺序表的Iterator(顺序表可以使用List来接收)
    public static void main1(String[] args) {
        //ArrayList<Integer> list = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        //迭代器Iterator的使用练习:
        Iterator<Integer> iterator = list.listIterator();
        while (iterator.hasNext()) {
            Integer value =  iterator.next();
            if(value == 2)  list.remove(Integer.valueOf(2));
        }

        System.out.println(list);
    }
}
